<%@page contentType="text/html" pageEncoding="UTF-8" import="Modelo.*, java.util.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
    "http://www.w3.org/TR/html4/loose.dtd">
<%@page import = "java.util.*" %>
<%@page import = "Modelo.*" %>
<%@page import = "javax.swing.*" %>

<jsp:useBean id="proyecto" scope="request" class="Modelo.Proyecto" />
<%
//esto es para que no guarde en el cache la pagina
            response.setHeader("Cache-Control", "max-age=0");
            response.setHeader("Cache-Control", "no-cache");
            response.setHeader("Cache-Control", "no-store");
            response.setHeader("Pragma", "no-cache");
            response.setDateHeader("Expires", -1);
%>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Autoevaluacion</title>
        <link href="<%=request.getContextPath()%>/css/style.css" rel="stylesheet" type="text/css" media="screen" />
        <link type="text/css" href="<%=request.getContextPath()%>/jQuery/css/smoothness/jquery-ui-1.7.2.custom.css" rel="Stylesheet" />
        <script type="text/javascript" src="<%=request.getContextPath()%>/jQuery/js/jquery-1.3.2.min.js"></script>
        <script type="text/javascript" src="<%=request.getContextPath()%>/jQuery/js/jquery-ui-1.7.2.custom.min.js"></script>
        <script  type="text/javascript" src="<%=request.getContextPath()%>/jQuery/development-bundle/ui/ui.core.js"></script>
        <script  type="text/javascript" src="<%=request.getContextPath()%>/jQuery/development-bundle/ui/ui.draggable.js"></script>
        <script  type="text/javascript" src="<%=request.getContextPath()%>/jQuery/development-bundle/ui/ui.droppable.js"></script>

        <script type="text/javascript">
            $(function() {
                $("#accordion").accordion({
                    event: "mouseover"
                });
            });
        </script>
        <style type="text/css">
            #listaOrigen7 { height: 400px; float: left; width: 45%; min-height: 18em; background: #E0E0E0; padding: 1%; overflow: auto}
            * html .lista7 { height: 12em; } /* IE6 */
            .item7 { float: left; width: 280px; padding: 0.4em; margin: 0 0.4em 0.4em 0; text-align: left;list-style-type:none; }
            .titulo7{background: white; text-align: center}
            #listaDestino7 {  float: right; width: 45%; min-height: 18em; padding: 1%;  height: 400px; overflow: auto;
                              background: #E0E0E0}
            * html #trash { height: 18em; } /* IE6 */
            .titulo7{background: white; text-align: center}
        </style>

        <script  type="text/javascript">
            $(document).ready(function(){
                $(".item7").draggable({helper: 'clone' , cursor: 'move'});



                $(".lista7").droppable({
                    accept: ".item7",
                    drop: function(ev, ui) {
                        // Añado el objeto origen a la lista destino
                        $(this).append($(ui.draggable));
                    }
                });

                $("#botonResultado7").click(function () {


                    $('.lista7 li').each(function () {
                        if($(this).parent().attr('id')=='listaDestino7'){
                            crearC($(this).attr('id'));

                        };

                        if($(this).parent().attr('id')=='listaOrigen7'){
                            EliminarC($(this).attr('id'));


                        };
                    });



                    document.form7.submit();

                });


            });


        </script>
        <script type="text/javascript">
            var num=0;
            var num1=0;
            // Funcion para crear lineas de objetos
            function crearC(idc) {
                num++;
                fi = document.getElementById('na7'); // 1
                contenedor = document.createElement('div'); // 2
                contenedor.id = 'div7'+num; // 3
                fi.appendChild(contenedor); // 4

                ele = document.createElement('input'); // 5
                ele.type = 'hidden'; // 6
                ele.name = 'caracteristica'+num;
                ele.id =idc;
                ele.value = idc;
                contenedor.appendChild(ele); // 7
            }

            function EliminarC(idc) {
                num1++;
                fi = document.getElementById('na7'); // 1
                contenedor = document.createElement('div'); // 2
                contenedor.id = 'div7'+num1; // 3
                fi.appendChild(contenedor); // 4

                ele = document.createElement('input'); // 5
                ele.type = 'hidden'; // 6
                ele.name = 'caracteristica-'+num1;
                ele.id =idc;
                ele.value = idc;
                contenedor.appendChild(ele); // 7
            }
        </script>
    </head>

    <body>
        <%
                    HttpSession s = request.getSession();
                    if (s.getAttribute("logged") != null && s.getAttribute("logged").equals(true)) {
                        Representante rrr = (Representante) s.getAttribute("representante");
        %>


        <div style="height: 400px">
            <%
                                    String idfactor = (String) request.getParameter("idf");
                                    Factor f = new Factor().findFactor(Long.parseLong(idfactor));
            %>
            <div align="right"  style="width: 640px; position: fixed; text-align: right"  >
                <a href="<%=request.getContextPath()%>/factor/crear.jsp"><img src="<%=request.getContextPath()%>/images/new.png"  style="border:0" alt="Crear"/></a>
                <a href="<%=request.getContextPath() + "/factor/detalle.jsp?idf=" + f.getId()%>"><img src="<%=request.getContextPath()%>/images/verq.png"  style="border:0" alt="Crear"/></a>
                <a href="<%=request.getContextPath()%>/factor/mostrar.jsp"><img src="<%=request.getContextPath()%>/images/list.png"  style="border:0" alt="Ver"/></a>
            </div>
            <form  name="form7" action="<%=request.getContextPath() + "/factor/editarFa.jsp"%>" method="POST">
                <h3>editar Factor</h3>
                <input type="hidden" name="idf" value="<%=f.getId()%>">
                <table border="0" class="form">
                    <tbody>
                        <tr>
                            <td> <p>nombre: </p></td>
                            <td> <input type="text" name="nombre" value="<%=f.getNombre()%>" /></td>
                        </tr>
                        <tr>
                            <td><p>descripcion: </p> </td>
                            <td> <input type="text" name="descripcion" value="<%=f.getDescripcion()%>" /></td>
                        </tr>
                    </tbody>
                </table>
                <h3>Caracteristicas</h3>
                <div>
                    <ul class="lista7" id="listaOrigen7">
                        <h4 class="titulo7"> Disponibles</h4>
                        <%


                                                List resultado = new Caracteristica().getLista();

                                                Iterator iterador = resultado.iterator();
                                                Caracteristica ca;

                                                while (iterador.hasNext()) {
                                                    ca = (Caracteristica) iterador.next();



                                                    if (ca.getFactor() == null) {
                        %>


                        <li class="item7" id="<%=ca.getId()%>"> <%=ca.getNombre()%></li>
                        <%
                                                    }
                                                }
                        %>
                    </ul>

                    <ul class="lista7" id="listaDestino7">
                        <h4 class="titulo7"> Seleccionadas</h4>

                        <%
                                                List resultado2 = new Caracteristica().getLista();
                                                Iterator iterador2 = resultado2.iterator();

                                                Caracteristica ca2;
                                                while (iterador2.hasNext()) {
                                                    ca2 = (Caracteristica) iterador2.next();
                                                    if (ca2.getFactor() != null && ca2.getFactor().getId().equals(f.getId())) {

                        %>

                        <li class="item7" id="<%=ca2.getId()%>"> <%=ca2.getNombre()%></li>

                        <%
                                                    }

                                                }
                        %>




                    </ul>

                </div>

                <div id="na7"></div>
                <p><input type="button" id="botonResultado7" value="guardar cambios" /></p>
            </form>
        </div>

        <%} else {
                        response.sendRedirect(request.getContextPath() + "/index.jsp");
                    }%>
    </body>
</html>

